﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Eloje_Data;
using eLoje_Model;

namespace ELoje_web
{
    public partial class MedidaNew : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                if (Session["DescMedida"] != null)
                    txtMedida.Text = Session["DescMedida"].ToString().Trim();
                if (Session["CodMedida"] != null)
                    hdnCodMedida.Value = Session["CodMedida"].ToString().Trim();
                if (Session["Status"] != null)
                    hdnStatus.Value = Session["Status"].ToString().Trim();

                applyText();
                navigationHistory();
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            MedidaDA da = new MedidaDA();
            if(!string.IsNullOrEmpty(hdnCodMedida.Value.Trim()))
                da.setAmendMedida(Convert.ToInt32(hdnCodMedida.Value), txtMedida.Text, hdnStatus.Value, "desenv", "A");
            else
                da.setNewMedida( txtMedida.Text, "desenv");


            Response.Redirect("~/Detalhes/MedidaList.aspx");
        }

        private void applyText()
        {
            btnSave.Text = "Salvar";
        }

        private void navigationHistory()
        {
            lblHistoryNavigation.Text = String.Format("{0} >> {1} >> {2} >>", "Cockpit", "Cadastros", "Medidas");
            lblThisPage.Text = "Nova Medida";

        }
    }
}